<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <title>Departamento</title>
    </h:head>
    <h:body>
        <p:layout fullPage="true">
            <p:layoutUnit position="north" size="110">
                <center><h1>Departamento</h1></center>
            </p:layoutUnit>
            <p:layoutUnit position="west" size="200" rendered="true" collapsible="true" resizable="true" closable="true" header="Menu">
                <h:form>
                    <p:commandLink value="Departamento" />
                </h:form>
            </p:layoutUnit>
            <p:layoutUnit position="center">  
                <h:form prependId="false">
                    <p:commandLink value="Criar novo departamento" actionListener="#{departamentoController.prepararAdicionarDepartamento(actionEvent)}" onclick="editor.show()"/>
                    <p:dialog widgetVar="editor" width="400" header="Departamento"   height="250"  
                              resizable="false" >  
                        <h:panelGrid columns="1" id="editorPainel">  
                            <h:panelGrid columns="2">  
                                <h:outputText  value="Nome:"  />  
                                <p:inputText id="nome" value="#{departamentoController.departamento.nome}">   
                                </p:inputText>  
                                <p:commandButton value="Salvar" actionListener="#{departamentoController.adicionar(actionEvent)}" update="departamentos" onclick="editor.hide();"/>  
                                <p:commandButton value="Cancelar"  onclick="editor.hide();
                                        return false;" />  
                            </h:panelGrid>  
                        </h:panelGrid>  
                    </p:dialog>                  
                    <p:dataTable id="departamentos" value="#{departamentoController.listaDepartamento}">
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Nome"/>
                            </f:facet>
                            <h:outputText value="#{derpatamento.nome}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Excluir"/>
                            </f:facet> 
                            <p:commandLink value="Excluir" action="#{departamentoController.excluir()}"
                                           onclick="if (!confirm('Deseja excluir o departamento #{derpatamento.nome}?'))
                                                       return false"  update="departamentos"/>
                        </p:column>         
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Editar"/>
                            </f:facet> 
                            <p:commandLink value="Editar" actionListener="#{departamentoController.prepararAlterarDependente(actionEvent)}" onclick="editor.show()"/>
                        </p:column>         
                    </p:dataTable>


                </h:form>
            </p:layoutUnit>
        </p:layout>
    </h:body>

</html>

